﻿@{
    ViewBag.Title = "updataUser";
    Layout = "~/Views/Shared/ShouYe.cshtml";
}

<link href="~/Content/css/bootstrap.min.css" rel="stylesheet" />
<script src="~/Scripts/js/jquery.min.js"></script>
<script src="~/Scripts/js/bootstrap.min.js"></script>
<script src="~/Scripts/jquery-1.8.2.min.js"></script>
<div class="col-lg-12">
    <div class="col-lg-6">
        <table class="tab-content table table-bordered table-striped table-responsive" style="margin-left:45%;margin-top:10px;">
            <tr>
                <td colspan="2" style="text-align:center">
                    <h2>请输入用户基本信息</h2>
                </td>
            </tr>
            <tr>
                <td>编号：</td>
                <td><input id="userid" type="text" value="@ViewBag.idlist[0].userID" readonly="readonly" /></td>
            </tr>
            <tr>
                <td>用户名：</td>
                <td>
                    <input id="yonghu" type="text" value="@ViewBag.idlist[0].userName" onblur="yonghus()" />
                    <span id="spanyonghu" style="color:#1653f1"></span>
                </td>
            </tr>
            <tr>
                <td>手机号：</td>
                <td>
                    <input id="shouji" type="text" onblur="phone()" value="@ViewBag.idlist[0].userPhone" />
                    <span id="spanphone" style="color:#55931c"></span>
                </td>
            </tr>
            <tr>
                <td>邮箱：</td>
                <td>
                    <input id="youxiang" type="email" value="@ViewBag.idlist[0].userEmail" onblur="email()" />

                    <span id="spanadd" style="color:red"></span>
                </td>
            </tr>
            <tr>
                <td>真实姓名：</td>
                <td>
                    <input id="name" type="text" onblur="mingzi()" value="@ViewBag.idlist[0].userRealname" />
                    <span id="spanname" style="color:#1653f1"></span>
                </td>
            </tr>
            <tr>
                <td>性别：</td>
                <td>
                    @if (@ViewBag.idlist[0].userSex == "男")
                    {
                        <p>
                            <input id="Radio1" name="sex" type="radio" value="男" checked="checked" />男
                            <input id="Radio1" name="sex" type="radio" value="女" />女
                        </p>
                    }
                    @if (@ViewBag.idlist[0].userSex == "女")
                    {
                        <p>
                            <input id="Radio1" name="sex" type="radio" value="男" />男
                            <input id="Radio1" name="sex" type="radio" value="女" checked="checked" />女
                        </p>
                    }
                </td>
            </tr>
            <tr>
                <td>年龄：</td>
                <td>
                    <input id="age" type="text" onblur="nianling()" value="@ViewBag.idlist[0].userAge" />
                    <span id="spanage" style="color:red"></span>
                </td>
            </tr>
            <tr>
                <td>用户状态：</td>
                <td>
                    <select id="sel">
                        @if (@ViewBag.idlist[0].userState == "等待入职")
                        {
                            <option value="等待入职" selected="selected">等待入职</option>
                            <option value="在职">在职</option>
                            <option value="兼职">兼职</option>
                            <option value="离职">离职</option>
                        }
                        @if (@ViewBag.idlist[0].userState == "在职")
                        {
                            <option value="等待入职">等待入职</option>
                            <option value="在职" selected="selected">在职</option>
                            <option value="兼职">兼职</option>
                            <option value="离职">离职</option>
                        }
                        @if (@ViewBag.idlist[0].userState == "兼职")
                        {
                            <option value="等待入职">等待入职</option>
                            <option value="在职">在职</option>
                            <option value="兼职" selected="selected">兼职</option>
                            <option value="离职">离职</option>
                        }
                        @if (@ViewBag.idlist[0].userState == "离职")
                        {
                            <option value="等待入职">等待入职</option>
                            <option value="在职">在职</option>
                            <option value="兼职">兼职</option>
                            <option value="离职" selected="selected">离职</option>
                        }
                    </select>
                </td>
            </tr>
            <tr>
                <td>用户角色：</td>
                <td>
                    <select id="roid">
                        @foreach (var item in ViewBag.chalist)
                        {
                            if (@ViewBag.idlist[0].RoleId == @item.RoleId)
                            {
                                <option value="@item.RoleId" selected="selected">@item.RoleName</option>
                            }
                            else
                            {
                                <option value="@item.RoleId">@item.RoleName</option>
                            }
                        }

                    </select>
                </td>
            </tr>
            <tr>
                <td><input id="Button1" type="button" onclick="quxiao()" value="取消" /></td>
                <td><input id="Button1" type="button" onclick="tijiao()" value="提交" /></td>
            </tr>
        </table>
    </div>
</div>
<script>
    function quxiao()
    {
        location.href = "/Home/showUser";
    }
        //用户名非空验证
        function yonghus() {
            var n = $("#yonghu").val();
            if (n.length == 0) {
                $("#spanyonghu").html("姓名不能为空哦。");
            }
            else {
                $("#spanyonghu").html("输入正确。");
            }
        }
        //邮箱验证
        function email() {
            var e = $("#youxiang").val();
            if (e.length == 0) {
                $("#spanadd").html("邮箱地址不可以为空哦！");
            }
            else {
                var etest = /^[a-zA-Z0-9_-]+@@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/;

                if (!etest.test(e)) {
                    $("#spanadd").html("请输入正确的邮箱！");
                }
                else {
                    $("#spanadd").html("输入正确。");

                }
            }
        }
        //手机验证
        function phone() {
            var p = $("#shouji").val();
            if (p.length == 0) {
                $("#spanphone").html("手机号不能为空。");
            }
            else {
                var ptest = /^1[3,5,7,8]\d{9}$/;
                if (!ptest.test(p)) {
                    $("#spanphone").html("请输入正确的大陆手机号。");
                }
                else {
                    $("#spanphone").html("输入正确。");
                }
            }
        }
        //姓名验证
        function mingzi() {
            var n = $("#name").val();
            if (n.length == 0) {
                $("#spanname").html("姓名不能为空哦。");
            }
            else {
                $("#spanname").html("输入正确。");
            }
        }
        //年龄验证
        function nianling() {
            var age = $("#age").val();
            var agetest = /^(1[89])|([2-7][0-9])|(80)$/;
            if (age.length == 0) {
                $("#spanage").html("请输入该用户的年龄。");
            }
            else {
                if (!agetest.test(age)) {
                    $("#spanage").html("请输入正确的年龄。");
                }
                else {
                    $("#spanage").html("输入正确。");


                }
            }
        }
        function tijiao() {
            var id = $("#userid").val();
            var name = $("#yonghu").val();
            var phone = $("#shouji").val();
            var email = $("#youxiang").val();
            var realname = $("#name").val();
            var sex = $("[name='sex']:checked").val();
            var age = $("#age").val();
            var sel = $("#sel").val();
            var roid = $("#roid").val();
            if (name.length == 0) {
                $("#spanyonghu").html("姓名不能为空哦。");
            }
            else {
                $("#spanyonghu").html("");
                if (phone.length == 0) {
                    $("#spanphone").html("手机号不能为空。");
                }
                else {
                    var ptest = /^1[3,5,7,8]\d{9}$/;
                    if (!ptest.test(phone)) {
                        $("#spanphone").html("请输入正确的大陆手机号。");
                    }
                    else {
                        $("#spanphone").html("");

                        if (email.length == 0) {
                            $("#spanadd").html("邮箱地址不可以为空哦！");
                        }
                        else {
                            var etest = /^[a-zA-Z0-9_-]+@@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/;

                            if (!etest.test(email)) {
                                $("#spanadd").html("请输入正确的邮箱！");
                            }
                            else {
                                $("#spanadd").html("");

                                if (realname.length == 0) {
                                    $("#spanname").html("姓名不能为空哦。");
                                }
                                else {
                                    $("#spanname").html("");

                                    var agetest = /^(1[89])|([2-7][0-9])|(80)$/;
                                    if (age.length == 0) {
                                        $("#spanage").html("请输入该用户的年龄。");
                                    }
                                    else {
                                        if (!agetest.test(age)) {
                                            $("#spanage").html("请输入正确的年龄。");
                                        }
                                        else {
                                            $("#spanage").html("");
                                            $.ajax({
                                                url: "/Home/updateUserDo",
                                                type: "post",
                                                data: { userID: id, userName: name, userPhone: phone, userEmail: email, userRealname: realname, userSex: sex, userAge: age, userState: sel, RoleId: roid },
                                                success: function (obj) {

                                                    if (obj > 0) {
                                                        location.href = "/Home/showUser";
                                                    }
                                                    else {
                                                        alert("修改失败，请重新修改。");
                                                        location.href = "/Home/showUser";
                                                    }
                                                }
                                            })

                                        }
                                    }
                                }

                            }
                        }
                    }
                }

            }

        }
</script>

